<?php
namespace App\Http\ViewComposers;

use App\Events\SystemNotify;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Models\Group;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use App\Models\User;
use App\Models\Register;
use App\Models\RegUser;
use App\Models\Company;


//pc端头部共用
class PcHeadComposer
{
    private $user;
    private $corpid;
    private $ucom;
    private $uri_cate;

    public function __construct()
    {
        if(empty(Auth::user())){
            abort(403,'登录信息错误');
        }
        $user = Auth::user()->comuser();
        if(empty($user)){
            abort(403,'登录信息错误');
        }
        $this->user = $user;
        $this->corpid = $user->corpid;
        $this->ucom = Company::where('id',$user->corpid)->first();
        $this->uri_cate = $this->dealuri();

    }
    
    public function dealuri()
    {
        $uri_cate = 1;
        $uri = $_SERVER['REQUEST_URI'];
        if(!strpos($uri ,"attendance") === false){
            $uri_cate = 2;
        }
        if(strpos($uri ,"sysadmin/group") !== false || strpos($uri ,"sysadmin/permission") !== false){
            $uri_cate = 1;
        }
        if(!strpos($uri ,"achievement") === false){
            $uri_cate = 3;
        }
        if(!strpos($uri ,"applylist") === false){
            $uri_cate = 4;
        }
        if(!strpos($uri ,"company-vip") === false || !strpos($uri ,"buy-vip") === false){
            $uri_cate = 5;
        }
        if(!strpos($uri ,"export-excel") === false){
            $uri_cate = 6;
        }
        return $uri_cate;
    }

    public function compose(View $view)
    {
        $view->with('comuser',$this->user);
        $view->with('ucom',$this->ucom);
        $view->with('uri_cate',$this->uri_cate);
    }
}